home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2371 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  73 lines

  1. Newsgroups: comp.lang.c
  2. Path: Utrecht.NL.net!news
  3. From: E.H.Terwiel@inter.NL.net (E.H. Terwiel (Erik))
  4. Subject: Re: ** Array problem **
  5. X-Nntp-Posting-Host: utr98-17.utrecht.nl.net
  6. Message-ID: <DLI1Lo.IsM@inter.NL.net>
  7. Sender: news@inter.NL.net (News at newsutr)
  8. Organization: NLnet
  9. X-Newsreader: Forte Free Agent 1.0.82
  10. References: <4dqh8k$ov9@neptunus.pi.net>
  11. Date: Sat, 20 Jan 1996 21:38:44 GMT
  12.  
  13. mv@pi.net wrote:
  14.  
  15.  
  16. >Hello Bill Wendlig (and everybody else),
  17.  
  18.  
  19. >A couple a days ago you replied to a message from me about some
  20. >problems with a piece if code..
  21. >You handed me some tips and corrections about a double indexed array that
  22. >turned out to be a 3-dimensional one..
  23.  
  24. >I implemented you corrections but to no good, it made things even worse...
  25. >But than again I'm not a an experienced C-programmer..
  26.  
  27. >But could you please tell me why this code works...
  28.  
  29.  
  30. >--------------------------------------------
  31.  
  32. >#include <stdio.h>
  33. >#include <stdlib.h>
  34. >#include <string.h>
  35. >#include <malloc.h>
  36.  
  37.  
  38. >char *s;
  39. >char a[20][20];
  40.  
  41.  
  42.  
  43. >int main (void)
  44.  
  45. >{
  46. > int i=0;
  47.  
  48. >  s=(char *)malloc(18);
  49. >   strcpy(s,"Blah blah, this works");
  50. >    for (i=0; i<=15; i++)
  51. >     {
  52. >      strcpy(a[i],s);
  53. >     }
  54. >    for (i=0; i<=15; i++)
  55. >     {
  56. >      printf("%s\n",a[i]);
  57. >     }
  58. >  free(s);
  59. > return 0;
  60. >}
  61.  
  62. >--------------------------------
  63.  
  64. >This is the same situation but it works fine here ?!
  65.  
  66.  
  67. Your blabla is too long for the mallec'ed space.
  68. It's even too long for the 'a' arrays !
  69. the blabla string is 21 chars long (remember the teminating 0 ?
  70.  
  71. Erik.
  72.  
  73.